<?php
include_once 'mod.php';
$mod = new mod();
if ($_SERVER['REQUEST_METHOD']=='POST'){
    $login_name = $_POST['login_name'];
    $name = $_POST['name'];
    $password = $_POST['password'];
    if (empty($login_name)){
        die('用户名不能为空<a href="register.php">重新注册</a>');
    }
    if (empty($name)){
        die('姓名不能为空<a href="register.php">重新注册</a>');
    }
    if (empty($password)){
        die('密码不能为空<a href="register.php">重新注册</a>');
    }
    $mysql = $mod->link();
    $sql = "select * from user where `login_name` = '$login_name'";
    $result = $mod->select($mysql,$sql);
    if ($result[0]['login_name']==$login_name){
        die('账户已存在，<a href="login.php">前往登录</a>------<a href="register.php">重新注册</a>');
    }
    $sql = "insert into user(`login_name`,`name`,`password`) values ('$login_name','$name',$password)";
    $result = $mod->IDU($mysql,$sql);
    if ($result['flag']){
        die('注册成功<a href="login.php">前往登录</a>');
    }else{
        die('注册失败:'.$result['msg'].'<a href="register.php">重新注册</a>');
    }
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册</title>
</head>
<body>
<form action="" method="post">
    <p>用户名:<input type="text" name="login_name"></p>
    <p>真实姓名:<input type="text" name="name"></p>
    <p>密码:<input type="password" name="password"></p>
    <input type="submit" value="注册">
</form>
</body>
</html>
